package com.taketoma818.NumberPicker;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class NumberPickerActivity extends Activity implements NumberPickerDialog.OnNumberChangedListener{

	private final static int NUMBER_1 = 0;
	private final static int NUMBER_2 = 1;
	private TextView textView1;
	private TextView textView2;
	private Button button1;
	private Button button2;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        textView1 = (TextView)findViewById(R.id.text1);
        textView2 = (TextView)findViewById(R.id.text2);
        button1 = (Button)findViewById(R.id.button1);
        button1.setOnClickListener(new View.OnClickListener() {
        	public void onClick(View view) {
        		showNumberPicker(textView1.getText().toString(),NUMBER_1);
        	}
        });
        button2 = (Button)findViewById(R.id.button2);
        button2.setOnClickListener(new View.OnClickListener() {
        	public void onClick(View view) {
        		showNumberPicker(textView2.getText().toString(),NUMBER_2);
        	}
        });
    }
    private void showNumberPicker(String number, int mode){
    	int nowNumber = 0 ;
    	int minNumber = 0 ;
    	int maxNumber = 255 ;
    	if (!number.equals("")){
    		nowNumber = Integer.parseInt(number);
    	}

    	new NumberPickerDialog(this, this, nowNumber, maxNumber, minNumber, mode).show();
    }
	@Override
	public void numberChanged(int number, int mode) {
		if (mode == NUMBER_1){
			textView1.setText(String.valueOf(number));
		}else{
			textView2.setText(String.valueOf(number));
		}
	}
}